clear
set more off

use "$statadir/rest_by_city", clear

qui replace city = "ALL ELSE" if city == ""
qui replace city = city + ", D.C." if city == "WASHINGTON"


local city1 "NEW YORK"
local city2 "LOS ANGELES"
local city3 "CHICAGO"
local city4 "SAN FRANCISCO"
local city5 "PHILADELPHIA"
local city6 "SEATTLE"
local city7 "WASHINGTON, D.C."
local city8 "ALL ELSE"
tempfile touse
qui save `touse', replace

cap file close myfile
file open myfile using "$outdir/tables/rest_by_city.tex", write replace

file write myfile " & Share with ERC on & Share with ERC on & Share with ERC on & Sample size \\ "
file write myfile " & original return & amended return & either type of return \\ "
file write myfile " & (1) & (2) & (3) & (4) \\ "
file write myfile "\midrule" _n


local rest1 1
local rest2 0

local panelstr1 Restaurants
local panelstr2 All other firms, size-matched

forval panel = 1/2 {
	// write panel header
	file write myfile " \textit{Panel `panel': `panelstr`panel''} \\ \addlinespace[6pt]  "
	forval i = 1/8 {

		use `touse' if city == "`city`i''" & restaurant == `rest`panel'', clear
		
		
		
		
		local e1 = proper("`city`i''")
		local e2 : di %6.3f any_ertc[1]
		local e3 : di %6.3f any_amendment[1]
		local e4 : di %6.3f either[1]
		
		local e5 = round(n,100)
		local e5 : di %10.0fc `e5'
		
		
		file write myfile " `e1' "
		forval j = 2/5 {
			file write myfile " & `e`j'' "
		}
		file write myfile " \\ "
		
		if `i' == 7 {
			file write myfile  " \hline "
		}
		
		if `i' < 8  {
			file write myfile " \addlinespace[6pt] "
		}
			

	}
	
	if `panel' == 1 {
		file write myfile "\hline \hline"
	}
}
cap file close myfile



// also, what's the grand mean?
use `touse' if restaurant == 1 & city ~= "ALL ELSE", clear
sum either [aw=n]


